package com.bdqn.t296.noso;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.t296.noso.entity.ReportVo;
import com.bdqn.t296.noso.entity.User;
import com.bdqn.t296.noso.mapper.PrescriMapper;
import com.bdqn.t296.noso.mapper.UserMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;

@SpringBootTest
@RunWith(SpringRunner.class)
public class PrescriService {

    @Resource
    PrescriMapper prescriMapper;
    @Resource
    UserMapper userMapper;
   /* @Test
    public void testPagination() {// 分页查询
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<User>();//条件构造器
        userQueryWrapper.eq("u.usr_role_id", 2L);
        userQueryWrapper.like("u.usr_name", "%磊%");//查询条件：角色 Id 为 2
        //分页对象：查询获得 User 对象，查看第 1 页数据，每页显示 2 条记录
        Page<User> page = new Page<User>(1, 2);
        IPage<User> userPager = userMapper.selectUser(page, userQueryWrapper);
        System.out.println("总记录数 ---- --> " + userPager.getTotal());
        System.out.println("总页数 ------ --> " + userPager.getPages());
        System.out.println("当前页数 ----- -> " + userPager.getCurrent());
        System.out.println("每页记录数 -----> " + userPager.getSize());
        System.out.println("当前记录： -----> ");
        for (User user : userPager.getRecords()) {//获得查询记录
            System.out.println("userName：" + user.getUsrName());
            System.out.println("user_role_id：" + user.getRoleName());
        }
    }*/

    @Test
    public void testPrescr() {
        QueryWrapper<ReportVo> wrapper = new QueryWrapper<ReportVo>();//条件构造器
        wrapper.like("r.reportName", "%王%");
        //分页对象：查询获得 User 对象，查看第 1 页数据，每页显示 2 条记录
        Page<ReportVo> page = new Page<ReportVo>(1, 2);
        IPage<ReportVo> userPager = prescriMapper.mobu(page, wrapper);
        System.out.println("总记录数 ---- --> " + userPager.getTotal());
        System.out.println("总页数 ------ --> " + userPager.getPages());
        System.out.println("当前页数 ----- -> " + userPager.getCurrent());
        System.out.println("每页记录数 -----> " + userPager.getSize());
        System.out.println("当前记录： -----> ");
        for (ReportVo reportVo : userPager.getRecords()) {//获得查询记录
            System.out.println("Name1111：" + reportVo.getReportName());
        }
    }

    @Test
    public void doLogin() {
        QueryWrapper<User> wrapper = new QueryWrapper<User>();
        wrapper.eq("loginname", "admin");
        User user = userMapper.selectOne(wrapper);
        System.out.println("User:" + user);
    }
}
